home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 January / PC Plus Super CD No55a (PCP-147A-1-99) (Disc 1) (1998).iso / linux / developers / visualtcl / windows / vtcl / lib / editor.tcl < prev    next >
Encoding:
Text File  |  1997-09-02  |  7.6 KB  |  203 lines

  1. ##############################################################################
  2. # $Id: editor.tcl,v 1.1 1997/09/03 05:11:07 stewart Exp $
  3. #
  4. # editor.tcl - a simple text editor
  5. #
  6. # Copyright (C) 1996-1997 Stewart Allen
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. ##############################################################################
  23. #
  24.  
  25. proc vTcl:editor:load_images {} {
  26.     global vTcl
  27.     foreach i {new open save cut copy paste search srchfwd srchbak} {
  28.         image create photo "editor_$i" \
  29.             -file [file join $vTcl(VTCL_HOME) images edit $i.gif]
  30.     }
  31. }
  32.  
  33. proc vTclWindow.editor {base} {
  34.     if {$base == ""} {
  35.         set base .vTcl.editor
  36.     }
  37.     if {[winfo exists $base]} {
  38.         wm deiconify $base; return
  39.     }
  40.     ###################
  41.     # CREATING WIDGETS
  42.     ###################
  43.     toplevel $base -class Toplevel
  44.     wm focusmodel $base passive
  45.     wm geometry $base 436x395+253+154
  46.     wm maxsize $base 1009 738
  47.     wm minsize $base 1 1
  48.     wm overrideredirect $base 0
  49.     wm resizable $base 1 1
  50.     wm deiconify $base
  51.     wm title $base "Text Editor"
  52.     frame $base.cpd18 \
  53.         -borderwidth 1 -height 30 -relief raised -width 30 
  54.     menubutton $base.cpd18.01 \
  55.         -anchor w -menu $base.cpd18.01.02 -padx 4 -pady 3 -text File \
  56.         -width 4 
  57.     menu $base.cpd18.01.02 -tearoff 0 
  58.     $base.cpd18.01.02 add command  -accelerator Ctrl-N -label New 
  59.     $base.cpd18.01.02 add command  -accelerator Ctrl-O -label Open 
  60.     $base.cpd18.01.02 add command  -accelerator Ctrl-W -label Close 
  61.     $base.cpd18.01.02 add separator
  62.     $base.cpd18.01.02 add command  -accelerator Ctrl-S -label Save 
  63.     $base.cpd18.01.02 add command  -label {Save As} 
  64.     $base.cpd18.01.02 add separator
  65.     $base.cpd18.01.02 add command  -accelerator Ctrl-Q -label Exit 
  66.     menubutton $base.cpd18.03 \
  67.         -anchor w -menu $base.cpd18.03.04 -padx 4 -pady 3 -text Edit \
  68.         -width 4 
  69.     menu $base.cpd18.03.04 \
  70.         -tearoff 0 
  71.     menubutton $base.cpd18.05 \
  72.         -anchor w -menu $base.cpd18.05.06 -padx 4 -pady 3 -text Help \
  73.         -width 4 
  74.     menu $base.cpd18.05.06 \
  75.         -tearoff 0 
  76.     menubutton $base.cpd18.men19 \
  77.         -anchor w -menu $base.cpd18.men19.01 -padx 4 -pady 3 -text Goto \
  78.         -width 4 
  79.     menu $base.cpd18.men19.01 \
  80.         -tearoff 0 
  81.     frame $base.fra20 \
  82.         -borderwidth 1 -height 20 -relief raised -width 125 
  83.     frame $base.fra20.fra21 \
  84.         -height 85 -relief groove -width 194 
  85.     button $base.fra20.fra21.fra22 \
  86.         -borderwidth 1 -relief raised -image editor_new
  87.     button $base.fra20.fra21.fra23  -command "vTcl:editor:load $base.fra27.tex28" \
  88.         -borderwidth 1 -relief raised -image editor_open
  89.     button $base.fra20.fra21.fra24 \
  90.         -borderwidth 1 -relief raised -image editor_save
  91.     frame $base.fra20.fra25 \
  92.         -height 85 -relief groove -width 194 
  93.     button $base.fra20.fra25.01 \
  94.         -borderwidth 1 -relief raised -image editor_cut
  95.     button $base.fra20.fra25.02 \
  96.         -borderwidth 1 -relief raised -image editor_copy
  97.     button $base.fra20.fra25.03 \
  98.         -borderwidth 1 -relief raised -image editor_paste
  99.     frame $base.fra20.fra26 \
  100.         -height 85 -relief groove -width 194 
  101.     button $base.fra20.fra26.01 \
  102.         -borderwidth 1 -relief raised -image editor_search
  103.     button $base.fra20.fra26.02 \
  104.         -borderwidth 1 -relief raised -image editor_srchfwd
  105.     button $base.fra20.fra26.03 \
  106.         -borderwidth 1 -relief raised -image editor_srchbak
  107.     frame $base.fra27 \
  108.         -borderwidth 1 -height 75 -relief raised -width 125 
  109.     text $base.fra27.tex28 \
  110.         -height 9 -highlightthickness 0 -width 33 \
  111.         -xscrollcommand "$base.fra27.scr29 set" \
  112.         -yscrollcommand "$base.fra27.scr30 set" \
  113.         -wrap none
  114.     scrollbar $base.fra27.scr29 \
  115.         -command "$base.fra27.tex28 xview" -highlightthickness 0 \
  116.         -orient horiz 
  117.     scrollbar $base.fra27.scr30 \
  118.         -command "$base.fra27.tex28 yview" -highlightthickness 0 \
  119.         -orient vert 
  120.     frame $base.fra31 \
  121.         -borderwidth 1 -height 20 -relief raised -width 125 
  122.     ###################
  123.     # SETTING GEOMETRY
  124.     ###################
  125.     pack $base.cpd18 \
  126.         -in $base -anchor center -expand 0 -fill x -side top 
  127.     pack $base.cpd18.01 \
  128.         -in $base.cpd18 -anchor center -expand 0 -fill none -side left 
  129.     pack $base.cpd18.03 \
  130.         -in $base.cpd18 -anchor center -expand 0 -fill none -side left 
  131.     pack $base.cpd18.05 \
  132.         -in $base.cpd18 -anchor center -expand 0 -fill none -side right 
  133.     pack $base.cpd18.men19 \
  134.         -in $base.cpd18 -anchor center -expand 0 -fill none -side left 
  135.     pack $base.fra20 \
  136.         -in $base -anchor center -expand 0 -fill x -side top 
  137.     pack $base.fra20.fra21 \
  138.         -in $base.fra20 -anchor center -expand 0 -fill none -padx 3 -pady 2 \
  139.         -side left 
  140.     pack $base.fra20.fra21.fra22 \
  141.         -in $base.fra20.fra21 -anchor center -expand 0 -fill none -side left 
  142.     pack $base.fra20.fra21.fra23 \
  143.         -in $base.fra20.fra21 -anchor center -expand 0 -fill none -side left 
  144.     pack $base.fra20.fra21.fra24 \
  145.         -in $base.fra20.fra21 -anchor center -expand 0 -fill none -side left 
  146.     pack $base.fra20.fra25 \
  147.         -in $base.fra20 -anchor center -expand 0 -fill none -padx 3 -pady 2 \
  148.         -side left 
  149.     pack $base.fra20.fra25.01 \
  150.         -in $base.fra20.fra25 -anchor center -expand 0 -fill none -side left 
  151.     pack $base.fra20.fra25.02 \
  152.         -in $base.fra20.fra25 -anchor center -expand 0 -fill none -side left 
  153.     pack $base.fra20.fra25.03 \
  154.         -in $base.fra20.fra25 -anchor center -expand 0 -fill none -side left 
  155.     pack $base.fra20.fra26 \
  156.         -in $base.fra20 -anchor center -expand 0 -fill none -padx 3 -pady 2 \
  157.         -side left 
  158.     pack $base.fra20.fra26.01 \
  159.         -in $base.fra20.fra26 -anchor center -expand 0 -fill none -side left 
  160.     pack $base.fra20.fra26.02 \
  161.         -in $base.fra20.fra26 -anchor center -expand 0 -fill none -side left 
  162.     pack $base.fra20.fra26.03 \
  163.         -in $base.fra20.fra26 -anchor center -expand 0 -fill none -side left 
  164.     pack $base.fra27 \
  165.         -in $base -anchor center -expand 1 -fill both -side top 
  166.     grid columnconf $base.fra27 0 -weight 1
  167.     grid rowconf $base.fra27 0 -weight 1
  168.     grid $base.fra27.tex28 \
  169.         -in $base.fra27 -column 0 -row 0 -columnspan 1 -rowspan 1 -padx 1 \
  170.         -pady 1 -sticky nesw 
  171.     grid $base.fra27.scr29 \
  172.         -in $base.fra27 -column 0 -row 1 -columnspan 1 -rowspan 1 -padx 1 \
  173.         -pady 1 -sticky ew 
  174.     grid $base.fra27.scr30 \
  175.         -in $base.fra27 -column 1 -row 0 -columnspan 1 -rowspan 1 -padx 1 \
  176.         -pady 1 -sticky ns 
  177.     pack $base.fra31 \
  178.         -in $base -anchor center -expand 0 -fill x -side top 
  179. }
  180.  
  181. proc vTcl:editor:load {text} {
  182.     set file [vTcl:get_file open]
  183.     if {$file == ""} {
  184.         return
  185.     }
  186.     set f [open $file]
  187.     $text delete 0.0 end
  188.     $text insert end [read $f]
  189.     close $f
  190. }
  191.  
  192. source globals.tcl
  193. source file.tcl
  194.  
  195. toplevel .vTcl
  196. wm withdraw .
  197. wm withdraw .vTcl
  198. global vTcl; set vTcl(VTCL_HOME) /home/stewart/vtcl/vtcl
  199.  
  200. vTcl:editor:load_images
  201. vTclWindow.editor ""
  202.  
  203.